package com.lufei.dh.more;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lufei.dh.R;
import com.lufei.dh.more.Adapter.Adapter_more;
import com.lufei.dh.more.Bean.BeanItem;
import com.lufei.dh.more.Bean.BeanMore;
import com.lufei.dh.view.Mult.Bean.BeanData;
import com.lufei.dh.view.Mult.Bean.Song;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.lufei.dh.view.Mult.CateActivity.KJ;
import static com.lufei.dh.view.Mult.CateActivity.getJson;

/**
 * 版权：易金卡沃 版权所有
 * <p>
 * 作者：lufei
 * <p>
 * 创建日期：2018/6/25
 * <p>
 * 描述：
 * <p>
 * 修订历史：
 */
public class MoreActivity extends AppCompatActivity {
    @BindView(R.id.id_more_recyclerview)
    RecyclerView idMoreRecyclerview;
    private Adapter_more adapterMore;
    private List<BeanItem> data2 = new ArrayList<>();

    private List<BeanMore> data = new ArrayList<>();
    private List<Integer> integers = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more);
        ButterKnife.bind(this);
        setList();
        init();
    }



    private void init() {
        adapterMore = new Adapter_more(data, this);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        idMoreRecyclerview.setLayoutManager(linearLayoutManager);
//        idMoreRecyclerview.setLayoutManager(new GridLayoutManager(this,2));
        idMoreRecyclerview.setAdapter(adapterMore);
        adapterMore.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(MoreActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void setList() {
//        String s1 = this.getString(R.string.json);
        String s1 = getJson("more.json", this);
        try {
            JSONObject jsonObject = new JSONObject(s1);
            JSONObject result = jsonObject.optJSONObject("result");
            JSONArray jsonArray = result.optJSONArray("data");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject data = jsonArray.getJSONObject(i);
                int x = KJ(data);
                integers.add(x);
                this.data.add(new BeanMore(
                        data.optString("uniquekey"),
                        data.optString("title"),
                        data.optString("date"),
                        data.optString("category"),
                        data.optString("author_name"),
                        data.optString("url"),
                        data.optString("thumbnail_pic_s"),
                        data.optString("thumbnail_pic_s02"),
                        data.optString("thumbnail_pic_s03"),
                        x
                ));
            }
            Log.e("xxxz", integers.toString());
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e("xxxz", "11zzzz" + "\n" + e);
        }
    }
}
